﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.ComponentModel;

namespace Simulator
{
    public class Gateway : Block {
        /// <summary>
        /// переменная,
        /// хранящая направление
        /// </summary>
		private int m_direction = 0;
		
        /// <summary>
        /// класс возвращаемых значений
        /// </summary>
		public class Constants {
			public static int OK   = 0;
			public static int FAIL = -1;
			public static int OUT  = 1;
			public static int IN   = 2;
		}
		
        /// <summary>
        /// пустой конструктор
        /// </summary>
		public Gateway() {}
		
        /// <summary>
        /// установить направление шлюза
        /// </summary>
        /// <param name="direction"></param>
        /// <returns></returns>
		public int setDirection(int direction) {
			if((direction != Constants.OUT) 
				&& (direction != Constants.IN)) {
				return Constants.FAIL;
			}
			
			m_direction = direction;
			
			return Constants.OK;
		}
		
        /// <summary>
        /// узнать о направлении шлюза
        /// </summary>
        /// <param name="direction"></param>
        /// <returns></returns>
		public int getDirection(ref int direction) {
            if ((m_direction != Constants.OUT)
                && (m_direction != Constants.IN)) {
				return Constants.FAIL;
			}
			
			direction = m_direction;
			
			return Constants.OK;
		}
		
        /// <summary>
        /// положить сущность в следующий
        /// блок
        /// </summary>
        /// <param name="e"></param>
		public override void PutEntity(ref Entity e) {
            e.OwnerBlock = this;

			if(m_direction == Constants.OUT) {
                Prev.PutEntity(ref e);
			}
			
			if(m_direction == Constants.IN) {
                Next.PutEntity(ref e);
			}
		}
		
		/// <summary>
		/// ичего не делать - заглушка
		/// </summary>
		public override void ClearEntities() {}
	}
}
